#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //初始化线程对象
    thread=new mythread();
}

MainWindow::~MainWindow()
{
    delete ui;
}

//开启线程
void MainWindow::on_pushButton_clicked()
{
    thread->start(); //start会创建线程并自动执行run
}
//关闭线程
void MainWindow::on_pushButton_2_clicked()
{
    thread->terminate(); //终止线程，跟pthread_cancel
    //回收线程
    thread->wait();
}
